/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitassistMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.other.mapper.impl;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.*;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.*;
import com.yonyou.iuap.yms.replace.CollectionUtil;
import com.yonyou.ucf.mdf.app.isvdxq.other.entity.UnitassistEntity;
import com.yonyou.ucf.mdf.app.isvdxq.other.model.UnitassistEntityBean;
import java.sql.Types;
import java.util.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

@Repository
public class UnitassistMapperImpl  {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;
    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitassistMapper.selectAll
    
    public List<UnitassistEntityBean> selectAll(String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select b.*,a.productId,a.unitExchangeType,a.id as assistId, a.assistUnit,a.assistUnit_Name,a.assistUnitCount,a.mainUnitCount,a.productTemplate  from dxqyy_unitassist a   left join dxqyy_unit b on a.assistUnit = b.id  where b.isEnabled=1 and b.`ytenant_id`=?;\n";
        parameter.addParam(tenantId);

        ResultSetProcessor processor = new AutoBeanListProcessor(new UnitassistEntityBean());
        return (List<UnitassistEntityBean>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitassistMapper.updateByPrimaryKey
    
    public int updateByPrimaryKey(UnitassistEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxqyy_unitassist set `productId` = ?, `unitExchangeType` = ?, `assistUnit` = ?, `assistUnit_Name` = ?, `assistUnitCount` = ?, `mainUnitCount` = ?, `productTemplate` = ? where `id` = ?\n";
        parameter.addParamWithType(record.getProductId(), Types.VARCHAR);
		parameter.addParamWithType(record.getUnitExchangeType(), Types.VARCHAR);
		parameter.addParamWithType(record.getAssistUnit(), Types.VARCHAR);
		parameter.addParamWithType(record.getAssistUnit_Name(), Types.VARCHAR);
		parameter.addParamWithType(record.getAssistUnitCount(), Types.VARCHAR);
		parameter.addParamWithType(record.getMainUnitCount(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductTemplate(), Types.VARCHAR);
		parameter.addParamWithType(record.getId(), Types.BIGINT);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitassistMapper.insertBatch
    
    public Integer insertBatch(List<UnitassistEntity> insertBatch) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" insert into dxqyy_unitassist (`id`, `productId`, `unitExchangeType`, `assistUnit`, `assistUnit_Name`, `assistUnitCount`, `mainUnitCount`, `productTemplate`, `ytenant_id`) values ");
		if (CollectionUtil.isNotEmpty(insertBatch)) {
			String separator0 = " , ";
			for (int i = 0; i < insertBatch.size(); i++) {
				UnitassistEntity item = insertBatch.get(i);
				sqlBuilder.append(" (?, ?, ?, ?, ?, ?, ?, ?, ?) ");
				parameter.addParamWithType(item.getId(), Types.BIGINT);
				parameter.addParamWithType(item.getProductId(), Types.VARCHAR);
				parameter.addParamWithType(item.getUnitExchangeType(), Types.VARCHAR);
				parameter.addParamWithType(item.getAssistUnit(), Types.VARCHAR);
				parameter.addParamWithType(item.getAssistUnit_Name(), Types.VARCHAR);
				parameter.addParamWithType(item.getAssistUnitCount(), Types.VARCHAR);
				parameter.addParamWithType(item.getMainUnitCount(), Types.VARCHAR);
				parameter.addParamWithType(item.getProductTemplate(), Types.VARCHAR);
				parameter.addParamWithType(item.getTenant_id(), Types.VARCHAR);
				if (i < insertBatch.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
		}
		sqlBuilder.append(" ON DUPLICATE KEY UPDATE unitExchangeType=VALUES(unitExchangeType),assistUnit=VALUES(assistUnit), assistUnitCount=VALUES(assistUnitCount),mainUnitCount=VALUES(mainUnitCount) ");

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitassistMapper.insert
    
    public int insert(UnitassistEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "insert into dxqyy_unitassist (`id`, `productId`,  `unitExchangeType`, `assistUnit`, `assistUnit_Name`, `assistUnitCount`, `mainUnitCount`,  `productTemplate`, `ytenant_id`) values (?, ?,  ?, ?, ?,  ?, ?,  ?, ?)\n";
        parameter.addParamWithType(record.getId(), Types.BIGINT);
		parameter.addParamWithType(record.getProductId(), Types.VARCHAR);
		parameter.addParamWithType(record.getUnitExchangeType(), Types.VARCHAR);
		parameter.addParamWithType(record.getAssistUnit(), Types.VARCHAR);
		parameter.addParamWithType(record.getAssistUnit_Name(), Types.VARCHAR);
		parameter.addParamWithType(record.getAssistUnitCount(), Types.VARCHAR);
		parameter.addParamWithType(record.getMainUnitCount(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductTemplate(), Types.VARCHAR);
		parameter.addParamWithType(record.getTenant_id(), Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitassistMapper.selectCount
    
    public int selectCount(long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select count(1) from dxqyy_unitassist where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new ColumnProcessor(int.class);
        return (int) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitassistMapper.selectById
    
    public UnitassistEntity selectById(long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_unitassist where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new AutoBeanProcessor(new UnitassistEntity());
        return (UnitassistEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitassistMapper.deleteByPrimaryKey
    
    public int deleteByPrimaryKey(Long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "delete from dxqyy_unitassist where `id` = ?\n";
        parameter.addParamWithType(id, Types.BIGINT);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UnitassistMapper.selectByProId
    
    public List<UnitassistEntityBean> selectByProId(String proId, String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select b.*,a.productId,a.unitExchangeType,a.id as assistId, a.assistUnit,a.assistUnit_Name,a.assistUnitCount,a.mainUnitCount,a.productTemplate  from dxqyy_unitassist a   left join dxqyy_unit b on a.assistUnit = b.id  where a.productId=? and b.isEnabled=1 and a.`ytenant_id`=?;\n";
        parameter.addParam(proId);
		parameter.addParam(tenantId);

        ResultSetProcessor processor = new AutoBeanListProcessor(new UnitassistEntityBean());
        return (List<UnitassistEntityBean>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

}
